package com.mmlc.meimei.lichengkongjian.classify;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.mmlc.inter.InterAdapter;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.network.responsebean.PrepareResponseBean;
import com.mmlc.utils.ViewUtils;
import com.mmlc.utils.XUtils;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29.
 */
public class OrderFormAdapter extends InterAdapter<PrepareResponseBean.DataBean.GoodsListBean> {

    public OrderFormAdapter(Context context, List<PrepareResponseBean.DataBean.GoodsListBean> datas) {
        super(context, datas);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_order, parent, false);
            holder = new ViewHolder();

            holder.iv_order = ViewUtils.ViewHolder.get(convertView, R.id.iv_order);
            holder.tv_order_name = ViewUtils.ViewHolder.get(convertView, R.id.tv_order_name);
            holder.tv_order_specification = ViewUtils.ViewHolder.get(convertView, R.id.tv_order_specification);
            holder.tv_order_price = ViewUtils.ViewHolder.get(convertView, R.id.tv_order_price);
            holder.tv_order_number = ViewUtils.ViewHolder.get(convertView, R.id.tv_order_number);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        PrepareResponseBean.DataBean.GoodsListBean data = datas.get(position);
        XUtils.image(holder.iv_order, data.getImg_thumb(), ImageView.ScaleType.CENTER_INSIDE);
        if (!ViewUtils.isEmpty(data.getName()))
            holder.tv_order_name.setText(data.getName());
        if (!ViewUtils.isEmpty(data.getSpec()))
            holder.tv_order_specification.setText("颜色：" + data.getSpec());
        if (!ViewUtils.isEmpty(data.getPrice()))
            holder.tv_order_price.setText("¥ " + data.getPrice());
        if (!ViewUtils.isEmpty(data.getNum()))
            holder.tv_order_number.setText("x " + data.getNum());

//        holder.tv_order_number.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ToastUtils.showToast(((TextView) v).getText().toString());
//            }
//        });

        return convertView;
    }

    class ViewHolder {
        ImageView iv_order;
        TextView tv_order_name;
        TextView tv_order_specification;
        TextView tv_order_price;
        TextView tv_order_number;
    }
}
